//
//  Utils.h
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 11/23/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#ifndef OpenGLGame_Utils_h
#define OpenGLGame_Utils_h

#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r) green:(g) blue:(b) alpha:(a)]
#define UX_RELEASE_SAFELY(obj) [obj release]

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

float GetScaleForProportionalResize( CGSize theSize, CGSize intoSize, bool onlyScaleDown, bool maximize );
CGImageRef CreateCGImageFromUIImageScaledWithRGBA( UIImage* image, float scaleFactor );

@interface Utils : NSObject

+ (UIImage*)scaledToSizeWithRGBA:(CGSize)toSize image:(UIImage*)image;
+ (UIColor*)averageColorOfImage:(UIImage*)image rect:(CGRect)rect;
+ (bool)is568Height;

@end

short swapEndianness2Bytes(short s);
vm_size_t usedMemory(void);
vm_size_t freeMemory(void);
void logMemUsage(void);

#endif
